package com.amazon.ags.client.leaderboards;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import com.amazon.ags.api.AmazonGamesClient;
import com.amazon.ags.api.ErrorCode;
import com.amazon.ags.api.RequestResponse;
import com.amazon.ags.api.leaderboards.GetLeaderboardPercentilesResponse;
import com.amazon.ags.api.leaderboards.GetLeaderboardsResponse;
import com.amazon.ags.api.leaderboards.GetPlayerScoreResponse;
import com.amazon.ags.api.leaderboards.GetScoresResponse;
import com.amazon.ags.api.leaderboards.SubmitScoreResponse;
import com.amazon.ags.api.overlay.PopUpLocation;
import com.amazon.ags.client.AmazonGamesService;
import com.amazon.ags.client.GCResponseHandleImpl;
import com.amazon.ags.client.RequestResponseImp;
import com.amazon.ags.constants.LeaderboardFilter;
import com.amazon.ags.overlay.PopUpPrefs;

public class LeaderboardsServiceProxy
  implements LeaderboardsService
{
  private static final String FEATURE_NAME = "LB";
  private static final String TAG = "LB_" + LeaderboardsServiceProxy.class.getSimpleName();
  private AmazonGamesClient agClient;
  private AmazonGamesService amazonGamesService;
  private final Handler apiHandler;

  public LeaderboardsServiceProxy(AmazonGamesClient paramAmazonGamesClient, AmazonGamesService paramAmazonGamesService, Handler paramHandler)
  {
    this.amazonGamesService = paramAmazonGamesService;
    this.agClient = paramAmazonGamesClient;
    this.apiHandler = paramHandler;
  }

  private Bundle createRequestBundle()
  {
    return new Bundle();
  }

  private Bundle createRequestBundleWithFilter(String paramString, LeaderboardFilter paramLeaderboardFilter)
  {
    Bundle localBundle = createRequestBundle();
    localBundle.putString("LEADERBOARD_ID", paramString);
    localBundle.putString("LEADERBOARD_FILTER", paramLeaderboardFilter.toString());
    return localBundle;
  }

  private Bundle createRequestBundleWithFilter(String paramString, LeaderboardFilter paramLeaderboardFilter, int paramInt1, int paramInt2)
  {
    Bundle localBundle = createRequestBundle();
    localBundle.putString("LEADERBOARD_ID", paramString);
    localBundle.putString("LEADERBOARD_FILTER", paramLeaderboardFilter.toString());
    localBundle.putInt("LEADERBOARD_START_RANK", paramInt1);
    localBundle.putInt("LEADERBOARD_SCORES_COUNT", paramInt2);
    return localBundle;
  }

  private Bundle createRequestBundleWithLeaderboardId(String paramString)
  {
    Bundle localBundle = createRequestBundle();
    localBundle.putString("LEADERBOARD_ID", paramString);
    return localBundle;
  }

  private Bundle createRequestBundleWithScore(String paramString, long paramLong)
  {
    Bundle localBundle = createRequestBundle();
    localBundle.putLong("LEADERBOARD_SUBMIT_SCORE", paramLong);
    localBundle.putString("LEADERBOARD_ID", paramString);
    localBundle.putString("POP_UP_LOCATION", PopUpPrefs.INSTANCE.getLocation().toString());
    return localBundle;
  }

  public final void getLeaderboards(final GCResponseHandleImpl<GetLeaderboardsResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Get leaderboards called with handle. ");
    final Message localMessage = Message.obtain();
    localMessage.what = 9;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(new Bundle());
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new GetLeaderboardsResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void getPercentileRanks(final String paramString, final LeaderboardFilter paramLeaderboardFilter, final GCResponseHandleImpl<GetLeaderboardPercentilesResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Get percentiles called Asynchronously with handle and leaderboardId = " + paramString);
    final Message localMessage = Message.obtain();
    localMessage.what = 31;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(LeaderboardsServiceProxy.this.createRequestBundleWithFilter(paramString, paramLeaderboardFilter));
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new GetLeaderboardPercentilesResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public final void requestLocalPlayerScore(final String paramString, final LeaderboardFilter paramLeaderboardFilter, final GCResponseHandleImpl<GetPlayerScoreResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Request Local Player Score called on leaderboardId " + paramString + " Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 10;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(LeaderboardsServiceProxy.this.createRequestBundleWithFilter(paramString, paramLeaderboardFilter, 1, 1));
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new GetPlayerScoreResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public final void requestScores(final String paramString, final LeaderboardFilter paramLeaderboardFilter, final int paramInt1, final int paramInt2, final GCResponseHandleImpl<GetScoresResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Request Scores called on leaderboardId " + paramString + " Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 7;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(LeaderboardsServiceProxy.this.createRequestBundleWithFilter(paramString, paramLeaderboardFilter, paramInt1, paramInt2));
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new GetScoresResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void showLeaderboardsOverlay(final GCResponseHandleImpl<RequestResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Show achievements overlay called Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 27;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(LeaderboardsServiceProxy.this.createRequestBundle());
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new RequestResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void showRanksOverlay(final String paramString, final GCResponseHandleImpl<RequestResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Show ranks overlay called Asynchronously with handle and leaderboardId = " + paramString);
    final Message localMessage = Message.obtain();
    localMessage.what = 28;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(LeaderboardsServiceProxy.this.createRequestBundleWithLeaderboardId(paramString));
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new RequestResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public final void submitScore(final String paramString, final long paramLong, final GCResponseHandleImpl<SubmitScoreResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Submit Score " + paramLong + " called Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 8;
    final LeaderboardsReplyMessengerFactory localLeaderboardsReplyMessengerFactory = new LeaderboardsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localLeaderboardsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(LeaderboardsServiceProxy.this.createRequestBundleWithScore(paramString, paramLong));
          LeaderboardsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new SubmitScoreResponseImp(18, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.amazon.ags.client.leaderboards.LeaderboardsServiceProxy
 * JD-Core Version:    0.6.2
 */